
var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery;

//设置账龄
let goodsAge = [
        {name: "小于60天", value: 1},
        {name: "60天-180天", value: 2},
        {name: "180天-1年", value: 3},
        {name: "1年-2年", value: 4},
        {name: "2年以上", value: 5}
    ];
for (let i = 0; i < goodsAge.length; i++) {
    $("#goodsagerange").append("<option value=\"" + goodsAge[i].value + "\">" + goodsAge[i].name + "</option>");
}

layer.ready(function () {
    //获取仓库信息
    $.ajax({
        url: "transfer/getWarehouse",
        success: function (data) {
            if (data.status == 200) {
                for (let i in data.data) {
                    $("#warehouseCode").append("<option value=\"" + data.data[i].code + "\">" + data.data[i].name + "</option>");
                }
                form.render('select');
            }
        }
    });
});

form.render('select');
table.render({
    elem: '#inventoryaging',
    url: 'stock/getStockGoodsAgeByPage',
    cols: [[
        {field: 'lotNo', width: 120, title: '批次号', sort: true},
        {field: 'productCode', width: 120, title: '产品编码', sort: true},
        {field: 'specificationCode', width: 120, title: '规格编码', sort: true},
        {field: 'specificationExplanation', width: 120, title: '规格说明', sort: true},
        {field: 'warehouse', width: 120, title: '仓库名称', sort: true},
        {field: 'contractNo', width: 120, title: '合同号', sort: true},
        {field: 'contractTypeStr', width: 120, title: '合同类型', sort: true},
        {field: 'realQuantity', width: 120, title: '实际数量', sort: true},
        {field: 'lessThanSixtyDays', width: 120, title: '小于60天', sort: true},
        {field: 'oneHundredEighty', width: 120, title: '60天-180天', sort: true},
        {field: 'threeHundredSixty', width: 120, title: '180天-1年', sort: true},
        {field: 'sevenHundredTwenty', width: 120, title: '1年-2年', sort: true},
        {field: 'moreThanTwoYears', width: 120, title: '2年以上', sort: true},
        {field: 'productCname', width: 160, title: '产品中文名称', sort: true},
        {field: 'productEname', width: 160, title: '产品英文名称', sort: true},
        {field: 'productUnitPrice', width: 120, title: '成本单价', sort: true},
        {field: 'shareCostPrice', width: 160, title: '分摊费用单价', sort: true},
        {field: 'trayNumber', width: 120, title: '托盘入数', sort: true},
        {field: 'totalTray', width: 120, title: '总托盘', sort: true}
    ]]
    ,id: 'inventoryagingtableid'
    ,height: $(document).height() - $('#inventoryaging').offset().top - 50
    ,page: true
    ,limit: 100
    ,limits: [100,300,500]


});
form.on('submit(submitform)', function(data){
    table.reload('inventoryagingtableid', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        ,where: data.field
    }, 'data');
    return false;
});